﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using MyProject.JQueryStudies.Models;

namespace MyProject.JQueryStudies.Controllers
{
    public class AngularController : Controller
    {
        //
        // GET: /Angular/

        public ActionResult Index()
        {
            return View();
        }

        public JsonResult PortalServices()
        {
            return Json(null);
        }

        #region Phone

        public ActionResult PhoneIndex()
        {
            return View();
        }

        public JsonResult PhoneData(string phoneId = null)
        {
            MyList<Phone> phones = new MyList<Phone>();

            Phone phone = new Phone()
            {
                age = 13,
                id = "motorola",
                name = "Motorola DEFY\u2122 with MOTOBLUR\u2122",
                snippet = "Are you ready for everything life throws your way?",
                imageUrl = "/Images/Thumbnails/doc.png",
                description = "motorola description",

                additionalFeatures = "Contour Display, Near Field Communications (NFC),..."
            };

            phone.images.Add("/Images/Thumbnails/setting.png");
            phone.images.Add("/Images/Thumbnails/flow.png");

            phone.availability.Add("motorola availability 1");
            phone.availability.Add("motorola availability 2");

            phone.connectivity.infrared = true;

            phones.Add(phone);

            phones.Add(new Phone()
            {
                age = 14,
                id = "google",
                name = "Google",
                snippet = "Are you ready?",
                imageUrl = "/Images/Thumbnails/org.png",
                description = "google description"
            });

            if (String.IsNullOrEmpty(phoneId))
            {
                return Json(phones);
            }
            else
            {
                return Json(phones.First());
            }
        }

        #endregion

        #region Support Members

        public class Phone
        {
            public int age { get; set; }
            public string id { get; set; }
            public string name { get; set; }
            public string snippet { get; set; }
            public string imageUrl { get; set; }
            public string description { get; set; }

            public string additionalFeatures { get; set; }
            public IList<string> images { get; set; }
            public IList<string> availability { get; set; }

            public Connectivity connectivity { get; set; }

            public Phone()
            {
                images = new List<string>();
                availability = new List<string>();
                connectivity = new Connectivity();
            }
        }

        public class Connectivity
        {
            public bool infrared { get; set; }
            public bool gps { get; set; }
        }

        #endregion
    }
}
